<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Easy
  </div>
  <div>
   <h1 class="question_title">
    824. Number of Lines To Write String
   </h1>
   <p>
    We are to write the letters of a given string
    <code>
     S
    </code>
    , from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it is written on the next line. We are given an array&nbsp;
    <code>
     widths
    </code>
    , an array where widths[0] is the width of 'a', widths[1] is the width of 'b', ..., and widths[25] is the width of 'z'.
   </p>
   <p>
    Now answer two questions: how many lines have at least one character from
    <code>
     S
    </code>
    , and what is the width used by the last such line? Return your answer as an integer list of length 2.
   </p>
   <p>
    &nbsp;
   </p>
   <pre>
<strong>Example :</strong>
<strong>Input:</strong> 
widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
S = "abcdefghijklmnopqrstuvwxyz"
<strong>Output:</strong> [3, 60]
<strong>Explanation: </strong>
All letters have the same length of 10. To write all 26 letters,
we need two full lines and one line with 60 units.
</pre>
   <pre>
<strong>Example :</strong>
<strong>Input:</strong> 
widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
S = "bbbcccdddaaa"
<strong>Output:</strong> [2, 4]
<strong>Explanation: </strong>
All letters except 'a' have the same length of 10, and 
"bbbcccdddaa" will cover 9 * 10 + 2 * 4 = 98 units.
For the last 'a', it is written on the second line because
there is only 2 units left in the first line.
So the answer is 2 lines, plus 4 units in the second line.
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     Note:
    </strong>
   </p>
   <ul>
    <li>
     The length of
     <code>
      S
     </code>
     will be in the range&nbsp;[1, 1000].
    </li>
    <li>
     <code>
      S
     </code>
     will only contain lowercase letters.
    </li>
    <li>
     <code>
      widths
     </code>
     is&nbsp;an array of length
     <code>
      26
     </code>
     .
    </li>
    <li>
     <code>
      widths[i]
     </code>
     will be in the range of
     <code>
      [2, 10]
     </code>
     .
    </li>
   </ul>
  </div>
  <div>
   <h1 class="question_title">
    824. 写字符串需要的行数
   </h1>
   <p>
    我们要把给定的字符串
    <code>
     S
    </code>
    &nbsp;从左到右写到每一行上，每一行的最大宽度为100个单位，如果我们在写某个字母的时候会使这行超过了100 个单位，那么我们应该把这个字母写到下一行。我们给定了一个数组&nbsp;
    <code>
     widths
    </code>
    &nbsp;，这个数组&nbsp;widths[0] 代表 'a' 需要的单位，&nbsp;widths[1] 代表 'b' 需要的单位，...，&nbsp;widths[25] 代表 'z' 需要的单位。
   </p>
   <p>
    现在回答两个问题：至少多少行能放下
    <code>
     S
    </code>
    ，以及最后一行使用的宽度是多少个单位？将你的答案作为长度为2的整数列表返回。
   </p>
   <pre>
<strong>示例 1:</strong>
<strong>输入:</strong> 
widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
S = "abcdefghijklmnopqrstuvwxyz"
<strong>输出:</strong> [3, 60]
<strong>解释: 
</strong>所有的字符拥有相同的占用单位10。所以书写所有的26个字母，
我们需要2个整行和占用60个单位的一行。
</pre>
   <pre>
<strong>示例 2:</strong>
<strong>输入:</strong> 
widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]
S = "bbbcccdddaaa"
<strong>输出:</strong> [2, 4]
<strong>解释: 
</strong>除去字母'a'所有的字符都是相同的单位10，并且字符串 "bbbcccdddaa" 将会覆盖 9 * 10 + 2 * 4 = 98 个单位.
最后一个字母 'a' 将会被写到第二行，因为第一行只剩下2个单位了。
所以，这个答案是2行，第二行有4个单位宽度。
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     注:
    </strong>
   </p>
   <ul>
    <li>
     字符串&nbsp;
     <code>
      S
     </code>
     的长度在&nbsp;[1, 1000] 的范围。
    </li>
    <li>
     <code>
      S
     </code>
     只包含小写字母。
    </li>
    <li>
     <code>
      widths
     </code>
     是长度为&nbsp;
     <code>
      26
     </code>
     的数组。
    </li>
    <li>
     <code>
      widths[i]
     </code>
     &nbsp;值的范围在&nbsp;
     <code>
      [2, 10]
     </code>
     。
    </li>
   </ul>
  </div>
 </body>
</html>